import axios from "axios";
const baseURL = import.meta.env.PROD ? import.meta.env.VITE_API_BASE_URL : "/api";

const api = axios.create({
  baseURL: baseURL,
  timeout: 10000,
});

// 登录
export const login = (username: string, password: string) => api.post("/auth/login", { username, password });

// 退出登录
export const logout = () => api.post("/auth/logout");

// 获取文件列表
export const getFiles = (path = "/") => api.post("/files/list", { path });

// 下载文件，返回URL
export const downloadFile = (filePath: string) => `${baseURL}/files/download?filePath=${encodeURIComponent(filePath)}`;

// 上传文件，返回URL
export const uploadFile = () => `${baseURL}/files/upload`;

// 删除文件
export const deleteFile = (path: string) => api.post("/files/delete", { path });

// 重命名文件
export const renameFile = (sourcePath: string, targetPath: string) =>
  api.post("/files/rename", { sourcePath, targetPath });

// 创建目录
export const createDirectory = (path: string) => api.post("/files/create-directory", { path });

export default api;
